﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using ObjectTransposeApi;
using System.Collections;

namespace ObjectTransposeApiSystemTest.TestFixture
{
    [TestFixture]
    public class ToValueNumberTestFixture
    {
        public class ByteStructure
        {
            public byte Value { get; set; }
        }

        public class ShortStructure
        {
            public short Value { get; set; }
        }

        public class IntStructure
        {
            public int Value { get; set; }
        }

        public class LongStructure
        {
            public long Value { get; set; }
        }

        [Test]
        public void LongToIntTest()
        {
            IntStructure value = ObjectToValue.Copy<IntStructure>(new { Value = long.Parse("1") });

            // make sure the field was set
            Assert.AreEqual(value.Value, 1);
        }

        [Test]
        public void LongToIntTooLargeTest()
        {
            IntStructure value = ObjectToValue.Copy<IntStructure>(new { Value = long.Parse(int.MaxValue.ToString()) + 1 });

            // make sure the field was set
            Assert.AreEqual(value.Value, default(int));
        }

        [Test]
        public void LongToIntTooSmallTest()
        {
            IntStructure value = ObjectToValue.Copy<IntStructure>(new { Value = long.Parse(int.MinValue.ToString()) - 1 });

            // make sure the field was set
            Assert.AreEqual(value.Value, default(int));
        }

        [Test]
        public void LongToShortTooLargeTest()
        {
            ShortStructure value = ObjectToValue.Copy<ShortStructure>(new { Value = long.Parse(short.MaxValue.ToString()) + 1 });

            // make sure the field was set
            Assert.AreEqual(value.Value, default(short));
        }

        [Test]
        public void LongToShortTooSmallTest()
        {
            ShortStructure value = ObjectToValue.Copy<ShortStructure>(new { Value = long.Parse(short.MinValue.ToString()) - 1 });

            // make sure the field was set
            Assert.AreEqual(value.Value, default(short));
        }

        [Test]
        public void LongToByteTest()
        {
            ByteStructure value = ObjectToValue.Copy<ByteStructure>(new { Value = long.Parse("1")});

            // make sure the field was set
            Assert.AreEqual(value.Value, 1);
        }

        [Test]
        public void LongToByteTooLargeTest()
        {
            ByteStructure value = ObjectToValue.Copy<ByteStructure>(new { Value = long.Parse(byte.MaxValue.ToString()) + 1});

            // make sure the field was set
            Assert.AreEqual(value.Value, default(byte));
        }

        [Test]
        public void LongToByteTooSmallTest()
        {
            ByteStructure value = ObjectToValue.Copy<ByteStructure>(new { Value = long.Parse(byte.MinValue.ToString()) - 1});

            // make sure the field was set
            Assert.AreEqual(value.Value, default(byte));
        }

        [Test]
        public void IntToLongTest()
        {
            LongStructure value = ObjectToValue.Copy<LongStructure>(new { Value = int.Parse("1") });

            // make sure the field was set
            Assert.AreEqual(value.Value, 1);
        }

        [Test]
        public void IntToShortTest()
        {
            ShortStructure value = ObjectToValue.Copy<ShortStructure>(new { Value = int.Parse("1") });

            // make sure the field was set
            Assert.AreEqual(value.Value, 1);
        }

        [Test]
        public void IntToShortTooLargeTest()
        {
            ShortStructure value = ObjectToValue.Copy<ShortStructure>(new { Value = int.Parse(short.MaxValue.ToString()) + 1 });

            // make sure the field was set
            Assert.AreEqual(value.Value, default(short));
        }

        [Test]
        public void IntToShortTooSmallTest()
        {
            ShortStructure value = ObjectToValue.Copy<ShortStructure>(new { Value = int.Parse(short.MinValue.ToString()) - 1 });

            // make sure the field was set
            Assert.AreEqual(value.Value, default(short));
        }

        [Test]
        public void IntToByteTest()
        {
            ByteStructure value = ObjectToValue.Copy<ByteStructure>(new { Value = int.Parse("1")});

            // make sure the field was set
            Assert.AreEqual(value.Value, 1);
        }

        [Test]
        public void IntToByteTooLargeTest()
        {
            ByteStructure value = ObjectToValue.Copy<ByteStructure>(new { Value = int.Parse(byte.MaxValue.ToString()) + 1});

            // make sure the field was set
            Assert.AreEqual(value.Value, default(byte));
        }

        [Test]
        public void IntToByteTooSmallTest()
        {
            ByteStructure value = ObjectToValue.Copy<ByteStructure>(new { Value = int.Parse(byte.MinValue.ToString()) - 1});

            // make sure the field was set
            Assert.AreEqual(value.Value, default(byte));
        }

        [Test]
        public void ShortToLongTest()
        {
            LongStructure value = ObjectToValue.Copy<LongStructure>(new { Value = short.Parse("1") });

            // make sure the field was set
            Assert.AreEqual(value.Value, 1);
        }

        [Test]
        public void ShortToIntTest()
        {
            IntStructure value = ObjectToValue.Copy<IntStructure>(new { Value = short.Parse("1") });

            // make sure the field was set
            Assert.AreEqual(value.Value, 1);
        }
        
        [Test]
        public void ShortToByteTest()
        {
            ByteStructure value = ObjectToValue.Copy<ByteStructure>(new { Value = short.Parse("1") });

            // make sure the field was set
            Assert.AreEqual(value.Value, 1);
        }

        [Test]
        public void ShortToByteTooLargeTest()
        {
            ByteStructure value = ObjectToValue.Copy<ByteStructure>(new { Value = short.Parse(byte.MaxValue.ToString()) + 1 });

            // make sure the field was set
            Assert.AreEqual(value.Value, default(byte));
        }

        [Test]
        public void ShortToByteTooSmallTest()
        {
            ByteStructure value = ObjectToValue.Copy<ByteStructure>(new { Value = short.Parse(byte.MinValue.ToString()) - 1 });

            // make sure the field was set
            Assert.AreEqual(value.Value, default(byte));
        }

        [Test]
        public void ByteToLongTest()
        {
            LongStructure value = ObjectToValue.Copy<LongStructure>(new { Value = byte.Parse("1")});

            // make sure the field was set
            Assert.AreEqual(value.Value, 1);
        }

        [Test]
        public void ByteToIntTest()
        {
            IntStructure value = ObjectToValue.Copy<IntStructure>(new { Value = byte.Parse("1")});

            // make sure the field was set
            Assert.AreEqual(value.Value, 1);
        }

        [Test]
        public void ByteToShortTest()
        {
            ShortStructure value = ObjectToValue.Copy<ShortStructure>(new { Value = byte.Parse("1") });

            // make sure the field was set
            Assert.AreEqual(value.Value, 1);
        }
    }
}
